<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/views/global/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

<link rel="shortcut icon" href='static/images/global/seahello.ico' />
<link rel="Bookmark" href='static/images/global/seahello.ico' />

<link rel="stylesheet" type="text/css" href="static/bootstrap/css/frame.css" />
<link rel="stylesheet" type="text/css" href="static/css/global/generic.css" />

<link rel="stylesheet" type="text/css" href="static/css/module/seller.css" />
<link href="static/css/page/informationEdit.css" rel="stylesheet" type="text/css">
<link href="static/css/page/submitStore.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="static/javascript/global/common/DatePicker.js"></script>

<title>INFORMATION EDIT</title>
<%@include file="/views/global/AdminScripts.jsp" %>
</head>
<body class="submitBg">
<!-- 顶部导航条  -->
<%@include file="/views/global/header.jsp" %>
<!-- 顶部导航条结束  -->

<c:set var="pageName" value="information"></c:set>
<%@include file="/views/global/BuyerHeader.jsp" %>
<div class="form-container center font fontColorGray">
		
			<div class="form-content submit-form">
				<div class="form-heading row hrTableBorder">
					<div class="col-xs-11 form-title">账户信息 INFO</div>
					<div class="col-xs-1 form-href" style="text-align: right;">
						<a href="javascript:void(0)">编辑 EDIT</a>
					</div>
				</div>
				<div class="information-content hrTableBorder">
					<div class="col-xs-2">
					<form id="imageForm"  action="" method="post" enctype="multipart/form-data">
						<div class="user-drawing">
						    <div class="buyerImageAdded">
						       <c:choose>
						          <c:when test="${not empty user.userFileId  }">
						           <img  src="${fileServerBasePath }download/${user.userFileId }"/>
						          </c:when>
						           <c:otherwise>
						       <img src="static/images/module/image_upload/imageAddBlank.png" blank="true"/>
						       </c:otherwise>
						       </c:choose>
						      
						    </div>
							
							<div class="image-edit">
							<div class="addFileImageArea col-xs-3">
								<input id="addBuyerImageInput" name="addBuyerImage" class="addBuyerImage" type="file" accept="img/*" />
								<a href="javascript:void(0)" style="margin-top: -34px;display: block;">编辑 EDIT</a>
							</div>
								
							</div>
						</div>
					</form>
					</div>
					
					<div class="col-xs-8" style="margin-left: 50px;">
					<form id="submitUserBasicForm"  method="post">
					    <input type="hidden" id="userFileIdHidden" name="userFileId" value="${user.userFileId }"/>
					     <input type="hidden"  name="id" value="${user.id }"/>
						<div class="information-row">
							<span class="form-label">昵称 NICK NAME:</span> <span class="form-text">
								<input type="text" name="userNick"
								class="storeNameInput submitInput submitInputWider"
								value="${user.userNick }" />
							</span>
						</div>

						<div class="information-row">
							<span class="form-label">性别 SEX:</span> <span class="form-text">
							<select class="storeNameInput submitInput submitInputWider" name="gender" id="gender">
							    <option value="m" <c:if test="${user.gender eq 'm' }"> selected</c:if>>男</option>
							    <option value="f" <c:if test="${user.gender eq 'f' }"> selected</c:if>>女</option>
							</select>
							</span>
						</div>
						<div class="information-row">
							<span class="form-label">出生日期 DATE OF BIRTH:</span> <span class="form-text">
								<input type="text" name="birthday"
								class="storeNameInput submitInput submitInputWider" value="${user.birthdayStr }" onclick="setday(this)"/>
							</span>
						</div>
						</form>
						                      
						<div class="information-row">
							<span class="form-label">密码 PASSWORD: </span> <span class="form-text">
								*****************&nbsp;&nbsp;<input type="button" class="form-button"
								value="修改密码" onclick="$('#pwdarea').toggle();"></span>
						</div>
						<!-- 修改密码区域 -->
						<form id="passwordForm"  action="">
						<table id="pwdarea" class="tablearea">
							<thead>
								<tr>
									<td colspan="2">修改密码</td>
								</tr>
							</thead>
							<tr>
								<td>当前密码:</td>
								<td><input type="password" name="currentpwd"
									class="storeNameInput submitInput submitInputWider" value="" /></td>
							</tr>
							<tr>
								<td>新密码:</td>
								<td><input type="password" name="newpwd"
									class="storeNameInput submitInput submitInputWider" value="" /></td>
							</tr>
							<tr>
								<td>确认新密码:</td>
								<td><input type="password" name="confirmpwd"
									class="storeNameInput submitInput submitInputWider" value="" /></td>
							</tr>
							<tr>
								<td></td>
								<td><input type="button" class="form-cancel-button"
									value="取消修改" onclick="$('#pwdarea').toggle();"> <input
									id="changePassword" type="button" class="form-button" value="确认修改"
									style="float: right; margin-right: 100px;"></td>
							</tr>
						</table>
						</form>
						<!-- 修改密码结束 -->
                       <form id="emailForm"  action="">
						<div class="information-row">
							<span class="form-label">电子邮箱 EMAIL:</span> <span class="form-text">
								${user.email }&nbsp;&nbsp;<input type="button"
								class="form-button" value="修改邮箱"
								onclick="$('#emailarea').toggle();"></span>
							
						</div>

						<!-- 修改邮箱区域 -->
						<table id="emailarea" class="tablearea">
							<thead>
								<tr>
									<td colspan="2">修改邮箱</td>
								</tr>
							</thead>
							<tr>
								<td>新邮箱:</td>
								<td><input type="text" name="newemail"
									class="storeNameInput submitInput submitInputWider" value="" /></td>
							</tr>
							<tr>
								<td>确认新邮箱:</td>
								<td><input type="text" name="confirmemail"
									class="storeNameInput submitInput submitInputWider" value="" /></td>
							</tr>
							<tr>
								<td>登陆密码:</td>
								<td><input type="password" name="pwd"
									class="storeNameInput submitInput submitInputWider" value="" /></td>
							</tr>
							<tr>
								<td></td>
								<td><input type="button" class="form-cancel-button"
									value="取消修改" onclick="$('#emailarea').toggle();"> <input
									 id="emailChange" type="button" class="form-button" value="确认修改"
									style="float: right; margin-right: 100px;"></td>
							</tr>
						</table>
						</form>
						<!-- 修改邮箱结束 -->
                        <div class="error"></div>
					</div>
				</div>
				
				<div class="form-group row" style="margin-top: 30px;">
					<div class="col-xs-2">
						<button type="button" id="btnExit" class="btn btn-default"
							style="width: 113px; height: 40px; color: #fff; background: #b5b6b3; margin: 0 0 80px 250px;">CANCEL 取消</button>
					</div>
					<div class="col-xs-8">
						<div id="msg"></div>
					</div>
					<div class="col-xs-2">
						<button type="button" id="btnSave"
							class="btn btn-default pull-right"
							style="width: 100px; height: 40px; color: #fff; background: #47caf4; margin: 0 250px 80px 0;">POST 发布</button>
					</div>
			    </div>
			</div>
	</div>
<script type="text/javascript" src="static/javascript/module/generic.js"></script>

<!-- 页尾 -->
<%@include file="/views/global/footer.jsp" %>
<!-- 页尾结束 -->
  
</body>

<script type="text/javascript">
$(document).ready(function(){
	
	$("#btnSave").click(function(){
		$("#submitUserBasicForm").goAjax({
			url:"user/saveBasic",
			type: "POST",
			semantic:false,
			dataType: "json",
			success: function(jsonData) {
				if(true == jsonData.success){
					window.location.href="buyer/information"
				} else {
					art.dialog({title:"ERROR", icon: "error", content: "SAVE USER FAILURE,PLEASE REFRESH! "});
				}
			}
		});
		
		
	});
	
	$("#addBuyerImageInput").on('change', function(){
		$("#imageForm").goAjax({
			url:"upload",
			semantic:false,
			data:{},
			success: function(jsonData) {
				if("SUCCESS" == jsonData.state){
					$(".buyerImageAdded").empty();
					$(".buyerImageAdded").append("<img  src='"+jsonData.url+"'/>");
					$("#userFileIdHidden").attr("value",jsonData.fileId);
				} else {
					//art.dialog({title:"错误", icon: "error", content: "上传失败"});
				}
			}
		});
		//do someing
	});
});


$("#emailChange").click(function(){
	var newemail = $("input[name=newemail]").val();
	var pwd = $("input[name=pwd]").val();
	var confirmemail = $("input[name=confirmemail]").val();
	if(newemail!=confirmemail){
		art.dialog({title:"error", icon: "error", content: "new email  not equal confirm email", top: 100, lock: true});
	    return;
	}
	$("#emailForm").goAjax({
		url:'user/saveEmail',
		type: "POST",
		semantic:false,
		dataType: "json",
		data:{password:pwd,email:newemail},
		success: function(jsonData) {
			if(true == jsonData.success){
				window.location.href="buyer/information/edit"
			} else {
				art.dialog({title:"error", icon: "error", content: jsonData.message, top: 100, lock: true});
			}
		}
	});
	
	
});

$("#changePassword").click(function(){
	var currentpwd = $("input[name=currentpwd]").val();
	var newpwd = $("input[name=newpwd]").val();
	var confirmpwd = $("input[name=confirmpwd]").val();
	if(newpwd!=confirmpwd){
		art.dialog({title:"error", icon: "error", content: "new password  not equal confirm password", top: 100, lock: true});
	    return;
	}
	$("#passwordForm").goAjax({
		url:'user/savePassword',
		type: "POST",
		semantic:false,
		dataType: "json",
		data:{oldPassword:currentpwd,newPassword:newpwd},
		success: function(jsonData) {
			if(true == jsonData.success){
				window.location.href="buyer/information/edit"
			} else {
				art.dialog({title:"error", icon: "error", content: jsonData.message, top: 100, lock: true});
			}
		}
	});
	
	
});
</script>
</html>
